﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vroom.Utils.Logging
{
	public class AuditData
	{
		public string GetAuditData(string LoaderGuid, string loaderName, DateTime start, DateTime end, string error, int insertCount, int? updateCount)
		{
			string auditData =  "<AuditData><PackageExecution><PackageId>" + LoaderGuid + "</PackageId><PackageName>" + loaderName + "</PackageName>" +
				   "<StartTime>" + start.ToString() +  "</StartTime><EndTime>" + end.ToString() + "</EndTime>" +
				   "<UserName>"  + Environment.UserDomainName + @"\" + Environment.UserName + "</UserName>" +
				   "</PackageExecution><AuditDetails>";

			if (!string.IsNullOrEmpty(error))
				auditData += "<Errors><Error>" + error + "</Error></Errors>";

            auditData += "<RowCounts>";

			if (insertCount > 0)
				auditData += "<Inserted>" + insertCount.ToString() +  "</Inserted>";
            else
                auditData += "<Inserted>0</Inserted>";

            if (updateCount > 0)
                auditData += "<Updated>" + updateCount.ToString() + "</Updated>";
            else
                auditData += "<Updated>0</Updated>";
    
            auditData += "</RowCounts>";

			auditData += "</AuditDetails></AuditData>";

            return auditData.Replace(@"&", @"&amp;").Replace(@"""", @"&quot;").Replace(@"'", @"&#39;"); //encode special chars
		}
	}
}
